//
// Created by guanyicheng on 2022/5/7.
//

#include "../../common.h"

class Solution {
public:
    int evalRPN(vector<string> &tokens) {
        auto opSet = unordered_set<string>{"+", "-", "*", "/"};
        auto _stack = stack<int>{};
        for (string s: tokens) {
            if (!opSet.count(s)) {
                _stack.emplace(stoi(s));
                continue;
            }
            int b = _stack.top();
            _stack.pop();
            int a = _stack.top();
            _stack.pop();
            int r;
            if (s == "+") {
                r = a + b;
            } else if (s == "-") {
                r = a - b;
            } else if (s == "*") {
                r = a * b;
            } else if (s == "/") {
                r = a / b;
            }
            _stack.emplace(r);
        }
        return _stack.top();
    }
};

int main() {
    auto s = vector<string>{"10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"};
    cout << Solution().evalRPN(s) << endl;
}